package game.model;

import java.util.Objects;

/**
 * 二维坐标类
 */
public class Position implements Cloneable {
    public int x; // 横坐标
    public int y; // 纵坐标

    /**
     * 构造函数，传入坐标
     *
     * @param x 横坐标
     * @param y 纵坐标
     */
    public Position(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Position obj = (Position) o;

        return Objects.equals(x, obj.x) && Objects.equals(y, obj.y);
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    @Override
    public String toString() {
        return "Position{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

    @Override
    public Position clone() {
        return new Position(x, y);
    }
}
